package com.zyt.mapper;

import com.zyt.pojo.Emp;
import com.zyt.pojo.EmpQueryParam;
import com.zyt.pojo.OperateLog;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * 员工信息
 */
@Mapper
public interface EmpMapper {
    //---------------------原始分页查询实现------------------------
//    /**
//     * 查询总记录数
//     *
//     */
//
//    @Select("select count(*) from emp e left join dept d on e.dept_id = d.id")
//    public Long count();
//    /*
//    * 分页查询
//     */
//    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id order by entry_date desc limit #{start},#{pageSize}")
//    public List<Emp> list(Integer start,Integer pageSize);
    //@Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id order by entry_date desc ")
    public List<Emp> list(EmpQueryParam empQueryParam);
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    void deleteByIds(List<Integer> ids);

    Emp getByid(Integer id);

    void updateByid(Emp emp);
    @MapKey("pos")
    List<Map<String,Object>> countEmpJobData();
    @MapKey("name")
    List<Map<String,Object>> countEmpGenderData();

    List<Emp> findAll();
@Select("select id,username,name from emp where username = #{username} and password = #{password}")
    Emp selectByUsernameAndPassword(Emp emp);

    @Select("select olg.id,olg.operate_emp_id operateEmpId, olg.operate_time, olg.class_name, olg.method_name, olg.method_params, olg.return_value, olg.cost_time, e.name operateEmpName from operate_log olg left join emp e on e.id = olg.operate_emp_id")
    List<OperateLog> selectLogPage();

}
